/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */

package org.openmrs.module.clinicalsummary.evaluator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.module.clinicalsummary.Constants;
import org.openmrs.util.OpenmrsUtil;

/**
 */
public final class EvaluatorUtils {

	private static final Log log = LogFactory.getLog(EvaluatorUtils.class);

	/**
	 * This class must not get instantiated
	 */
	private EvaluatorUtils() {
	}

	/**
	 * Get the output location of the evaluation process
	 *
	 * @param suffix the suffix path to the default folder
	 * @return the output location of the evaluation process
	 */
	public static File getOutputDirectory(String suffix) {
		List<String> pathFragments = new ArrayList<String>();

		if (StringUtils.isEmpty(suffix))
			suffix = "tmp";

		pathFragments.add(Constants.GENERATED_PDF_LOCATION);
		pathFragments.add(suffix);

		return OpenmrsUtil.getDirectoryInApplicationDataDirectory(StringUtils.join(pathFragments, File.separator));
	}

	/**
	 * Get the default xml file name based on the filename prefix
	 *
	 * @param prefix the prefix of the filename
	 * @return the xml filename
	 */
	public static String getXmlFilename(String prefix) {
		List<String> nameFragments = new ArrayList<String>();
		
		if (StringUtils.isEmpty(prefix))
			prefix = "temporary";
		
		nameFragments.add(prefix);
		nameFragments.add(Evaluator.FILE_TYPE_XML);

		return StringUtils.join(nameFragments, ".");
	}
}
